package com.sky.controller.admin;

import com.sky.dto.OrdersCancelDTO;
import com.sky.dto.OrdersConfirmDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersRejectionDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrderService;
import com.sky.vo.OrderStatisticsVO;
import com.sky.vo.OrderVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 目标:
 *
 * @author YUE
 * @date 2024/6/19 16:46
 */
@RestController
@Api(tags = "商家端订单接口")
@Slf4j
@RequestMapping("/admin/order")
public class UserOrderController {
    @Autowired
    private OrderService orderService;

    /*
       订单搜索 分页查询
     */
    @GetMapping("/conditionSearch")
    @ApiOperation("商家端订单搜索分页查询")
    public Result<PageResult> conditionSearch(OrdersPageQueryDTO ordersPageQueryDTO) {
        PageResult ordersPage = orderService.conditionSearch(ordersPageQueryDTO);
        return Result.success(ordersPage);
    }

    /*
       各个状态的订单数量统计
     */
    @GetMapping("/statistics")
    @ApiOperation("各个状态的订单数量统计")
    private Result<OrderStatisticsVO> statistics() {
        OrderStatisticsVO orderStatisticsVO = orderService.statistics();
        return Result.success(orderStatisticsVO);
    }

    /*
      查询订单详情
     */
    @GetMapping("/details/{id}")
    @ApiOperation("查询订单详情")
    private Result<OrderVO> getByDetail(@PathVariable Long id) {
        OrderVO vo = orderService.getDetailById(id);
        return Result.success(vo);
    }

    /*
       接单
     */
    @PutMapping("/confirm")
    @ApiOperation("接单")
    private Result confirm(@RequestBody OrdersConfirmDTO ordersConfirmDTO) {
        orderService.confirm(ordersConfirmDTO);
        return Result.success();
    }

    /*
       拒绝订单
      待接单状态可以进行拒单与接单操作，进行拒单操作需要选择拒单原因。
     */
    @PutMapping("/rejection")
    @ApiOperation("拒绝订单")
    public Result rejection(@RequestBody OrdersRejectionDTO ordersRejectionDTO) {
        orderService.rejection(ordersRejectionDTO);
        return Result.success();
    }

    /*
       取消订单
     */
    @PutMapping("/cancel")
    @ApiOperation("取消订单")
    public Result cancel(@RequestBody OrdersCancelDTO ordersCancelDTO) {
        orderService.adminCancel(ordersCancelDTO);
        return Result.success();
    }

    /*
      派送订单
     */
    @PutMapping("/delivery/{id}")
    @ApiOperation("派送订单")
    public Result delivery(@PathVariable Long id){
        orderService.delivery(id);
        return Result.success();

    }

    /*
       完成订单
     */
    @PutMapping("/complete/{id}")
    @ApiOperation("完成订单")
    public Result complete(@PathVariable Long id){
        orderService.complete(id);
        return Result.success();

    }
}
